﻿<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl" %>
<div id="wfset" style="padding-top: 35px;">
    <input type="button" onclick="showPostAdd()" value="添加岗位" />
    <input type="button" onclick="showRankAdd()" value="添加等级" />
    <input type="button" onclick="saveallchecked();" value="保存勾选内容" />
    <div id="menus">
        <div id="div_bd_main">
            <div style="width: 650px; float: left; margin-left: 10px; background-color: #F9F9F9;
                border: solid 1px #6C92AD;">
                <div id="div_bd" style="position: relative; height: 800px; width: 600px; margin-left: 13px;
                    overflow: auto; padding: 5px;">
                    <% Response.Write(ViewData["formdefi"]); %>
                </div>
                <div class="div_hide">
                </div>
            </div>
        </div>
    </div>
    <div id='postland' style="display: none;">
        <label>
            岗位名称</label>
        <input type="text" name='postname' id='postnameadd' />
        <a onclick='postAdd();'>确定</a>
    </div>
    <div id="rankland" style="display: none;">
        <label>
            等级名称</label>
        <input type="text" name="rankname" id='ranknameadd' />
        <a onclick='rankAdd();'>确定</a>
    </div>
</div>
<style type="text/css">
    .drop_self
    {
        border-bottom: 1px solid #3E99D4;
        border-right: 1px solid #3E99D4;
    }
    .drop_self > .input
    {
        border: 0px;
    }
    .drop_self > .mybutton
    {
        float: right;
    }
    .drop_self > .mybutton > .addbtn
    {
        width: 20px;
        float: left;
    }
    .drop_self > .mybutton > .selectbtn
    {
        width: 20px;
        float: left;
    }
    .drop_self > .options
    {
        position: absolute;
        margin: 0;
        padding: 0;
        list-style: none;
        border-bottom: 1px solid #3E99D4;
        border-left: 1px solid #3E99D4;
        border-right: 1px solid #3E99D4;
    }
    .drop_self > .options > li > a
    {
        width: 100%;
        height: 24px;
        color: #000;
        background: #fff;
        line-height: 24px;
        display: block;
        font-size: 14px;
        text-indent: 10px;
        text-decoration: none;
    }
    .drop_self > .options > li > a:hover
    {
        color: #fff;
        background: #50c0cd;
    }
</style>
<input type="hidden" id='postlist' value="<%=ViewData["postName"] %>" />
<input type="hidden" id="ranklist" value="<%=ViewData["rankName"] %>" />

<script type="text/javascript">
    $(function() {
        bandselect();
    })

    function bandselect() {
        var table = $("#updateTable").children("table");
        var trs = $(table).children("tbody").children("tr");
        var trcount = trs.length;


        for (var index = 1; index < trcount; index++) {
            var tds = $(trs[index]).children();
            var select = $(tds[2]).children();
            getoption(select[0]);
        }

        for (var index = 1; index < trcount; index++) {
            var tds = $(trs[index]).children();
            var select = $(tds[4]).children();
            getoption(select);
        }

    }


    function showPostAdd() {
        $("#postland").fadeIn();
    }

    function hidePostAdd() {
        $("#postland").fadeOut();
    }

    function postAdd() {
        var value = $("#postnameadd").val();
        if (value == "") {
            alert("岗位不能为空");
            hidePostAdd();
            return false;
        }
        $.ajax({
            type: "POST",
            url: "/Salary/AddPost",
            data: { "postname": value },
            success: function(data) {
                if (data != "Fail") {
                    alert("添加成功!");
                    $("#postlist").val(data);
                    bandselect();
                } else {
                    alert(value + " 岗位已经存在");
                    $("#postnameadd").val("");
                }
                hidePostAdd();
            }
        });
    }


    function showRankAdd() {
        $("#rankland").fadeIn();
    }

    function hideRankAdd() {
        $("#rankland").fadeOut();
    }

    function rankAdd() {
        var value = $("#ranknameadd").val();
        if (value == "") {
            alert("等级不能为空");
            hideRankAdd();
            return false;
        }
        $.ajax({
            type: "POST",
            url: "/Salary/AddRank",
            data: { "rankname": value },
            success: function(data) {
                if (data != "Fail") {
                    alert("添加成功!");
                    $("#ranklist").val(data);
                    bandselect();
                } else {
                    alert(value + " 等级已经存在");
                    $("#ranknameadd").val("");
                }
                hideRankAdd();
            }
        });
    }

    function checkAllSala(tag) {
        var tbody = $(tag).parent().parent().parent();
        var trs = $(tbody).children("tr");
        var trCount = trs.length;
        var checked = $(tag).attr("name");
        if (checked == "false") {
            for (var index = 1; index < trCount; index++) {
                var checkBox = $(trs[index]).children("td").children();
                $(checkBox).attr("checked", true);
            }
            $(tag).attr("name", "true");
        } else {
            for (var index = 1; index < trCount; index++) {
                var checkBox = $(trs[index]).children("td").children();
                $(checkBox).removeAttr("checked");
            }
            $(tag).attr("name", "false");
        }
    }

    function saveallchecked() {
        var table = $("#updateTable").children("table");
        var trs = $(table).children("tbody").children("tr");
        var trcount = trs.length;
        var result = "";
        for (var index = 1; index < trcount; index++) {
            var checked = $(trs[index]).children().children().attr("checked");
            if (checked == true) {
                result += producerecord(index) + ",";
            }
        }
        $.ajax({
            type: "POST",
            url: "/Salary/UpdateSalary",
            data: { "record": result },
            success: function(data) {
                if (data == "Success")
                    alert("保存成功");
                else
                    alert("发生未知错误,保存失败");
            }
        });

    }

    function savesalary(tag, rowIndex) {
        var result = producerecord(rowIndex);
        $.ajax({
            type: "POST",
            url: "/Salary/UpdateSalary",
            data: { "record": result },
            success: function(data) {
                if (data == "Success")
                    alert("保存成功");
                else
                    alert("发生未知错误,保存失败");
            }
        });
    }

    function producerecord(trIndex) {
        var index = parseInt(trIndex) + 1;
        var table = $("#updateTable").children("table");
        var trs = $(table).children("tbody").children("tr");
        var tds = $(trs[index]).children();

        var record = $(tds[0]).children(".tbvalget").val() + ";" + $(tds[1]).children(".tbvalget").val() + ";" + $(tds[2]).children(".tbvalget").val() + ";" + $(tds[3]).children(".tbvalget").val()
         + ";" + $(tds[4]).children(".tbvalget").val() + ";" + $(tds[5]).children(".tbvalget").val() + ";" + $(tds[6]).children(".tbvalget").val()
         + ";" + $(tds[7]).children(".tbvalget").val() + ";" + $(tds[8]).children(".tbvalget").val() + ";" + $(tds[9]).children(".tbvalget").val()
         + ";" + $(tds[10]).children(".tbvalget").val() + ";" + $(tds[11]).children(".tbvalget").val();
        return record;
    }

    function sumSalary(tag) {
        var val = $(tag).val();
        $(tag).parent().children(".tbvalget").val(val);
        var tr = $(tag).parent().parent();
        var tds = $(tr).children();
        var basesalary = $(tds[5]).children(".tbvalget").val();
        var postsalary = $(tds[6]).children(".tbvalget").val();
        var hosesubidy = $(tds[7]).children(".tbvalget").val();
        var phonesubsi = $(tds[8]).children(".tbvalget").val();


        var sum = 0.00;
        sum += basesalary == '' ? 0 : parseFloat(basesalary);
        sum += postsalary == '' ? 0 : parseFloat(postsalary);
        sum += hosesubidy == '' ? 0 : parseFloat(hosesubidy);
        sum += phonesubsi == '' ? 0 : parseFloat(phonesubsi);
        $(tds[9]).children(".tbvalget").val(sum);
        $(tds[9]).children("lable").html(sum);
    }
    function setvalue(tag) {
        var val = $(tag).val();
        $(tag).parent().children(".tbvalget").val(val);
    }

    function getoption(tag) {
        var cls = $(tag).attr("class");
        if (cls == "1") {
            $(tag).html($("#postlist").val());
        } else if (cls == '3') {
            $(tag).html($("#ranklist").val());
        }
        setvalue(tag);
    }
</script>

